﻿CREATE TABLE DBVERSION (
	ID		INTEGER NOT NULL,
    CURRENTVALUE INTEGER NOT NULL)
----------
INSERT INTO DBVERSION (ID, CURRENTVALUE) VALUES (1, 1)
----------
CREATE GENERATOR GEN_JOURNAL_ID;
----------
CREATE TABLE JOURNAL (
    ID        INTEGER NOT NULL,
    ID_USER   INTEGER,
    ID_TOVAR  INTEGER, 
	ID_PARTNER INTEGER,
    SALEDATE  DATE,
    AMOUNT    DECIMAL(15,2),
    PRICE     DECIMAL(15,2),
    DISCOUNT  DECIMAL(15,2),
	COMMENT	  VARCHAR(200)
);
----------
ALTER TABLE JOURNAL ADD CONSTRAINT PK_JOURNAL PRIMARY KEY (ID);
----------
CREATE OR ALTER TRIGGER JOURNAL_BI FOR JOURNAL
ACTIVE BEFORE INSERT POSITION 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gen_journal_id,1);
end
----------
DELETE FROM USERS;
----------
INSERT INTO USERS (LOGIN, PASS, RIGHTS) VALUES ('Administrator','manavhat1',1);